package br.com.sigde.framework.modelo;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import br.com.sigde.framework.exception.ServiceException;


public  class ConnectionProvider  {

	public static Connection getDefaultConnection() throws Exception{
		/*
		Connection conn =null;
		String driver = "oracle.jdbc.OracleDriver";
		String urlConnection = "jdbc:oracle:thin:@localhost:1521:xe";
		String user = "sigde";
		String password = "sigde";
		Class.forName(driver);
		*/
		Connection conn =null;
		String driver  = "org.postgresql.Driver";
		String urlConnection = "jdbc:postgresql://localhost:5432/postgres";
		String user = "gde";
		String password = "gde";
		Class.forName(driver);
		
		
		conn =  DriverManager.getConnection(urlConnection , user , password);
		conn.setAutoCommit(false);
		return conn;
	}
	
	public static void fechaConexao(Connection conn) throws ServiceException{
		if(conn!=null){
			
			try {
				conn.rollback();
			} catch (SQLException e) {
				
			}finally{
				try{
					
					conn.close();
					
				} catch (SQLException e) {
					throw new ServiceException(e);
				}
			}
		}
	}
}
